package com.xinqi.modules.course.demonstrate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.xinqi.common.base.enums.QrCodeEnum;
import com.xinqi.common.base.utils.RandomUtils;
import com.xinqi.common.base.utils.json.JSON;
import com.xinqi.common.core.constant.CacheConstants;
import com.xinqi.common.core.constant.ConfigKeyConstants;
import com.xinqi.common.core.enums.ClassRoleEnum;
import com.xinqi.common.redis.utils.RedisUtils;
import com.xinqi.modules.course.classmenu.service.ClassMenuService;
import com.xinqi.modules.course.clazz.convert.ClassConvert;
import com.xinqi.modules.course.clazz.domain.ClassEntity;
import com.xinqi.modules.course.clazz.domain.ClassJoinAuditEntity;
import com.xinqi.modules.course.clazz.domain.ClassOperationLogEntity;
import com.xinqi.modules.course.clazz.domain.ClassStudentEntity;
import com.xinqi.modules.course.clazz.mapper.ClassJoinAuditMapper;
import com.xinqi.modules.course.clazz.mapper.ClassMapper;
import com.xinqi.modules.course.clazz.mapper.ClassOperationLogMapper;
import com.xinqi.modules.course.clazz.mapper.ClassStudentMapper;
import com.xinqi.modules.course.clazz.service.ClassJoinAuditService;
import com.xinqi.modules.course.clazz.service.ClassOperationLogService;
import com.xinqi.modules.course.clazz.service.ClassService;
import com.xinqi.modules.course.clazz.service.ClassStudentService;
import com.xinqi.modules.course.course.domain.CourseEntity;
import com.xinqi.modules.course.course.enums.ClassAuditEnum;
import com.xinqi.modules.course.course.mapper.CourseMapper;
import com.xinqi.modules.course.demonstrate.bean.ClassDemoDTO;
import com.xinqi.modules.course.demonstrate.service.DemoClassService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 示范课程
 */
@Service("demoClassService")
@RequiredArgsConstructor
public class DemoClassServiceImpl implements DemoClassService {

    /**
     * 班级
     */
    private final ClassConvert classConvert;
    private final ClassMapper classMapper;
    private final ClassService classService;

    /**
     * 学生
     */
    private final ClassStudentMapper classStudentMapper;
    private final ClassStudentService classStudentService;

    /**
     * 加课记录
     */
    private final ClassJoinAuditMapper classJoinAuditMapper;
    private final ClassJoinAuditService classJoinAuditService;
    private final ClassOperationLogMapper classOperationLogMapper;
    private final ClassOperationLogService classOperationLogService;

    private final IdentifierGenerator identifierGenerator;
    private final CourseMapper courseMapper;
    private final ClassMenuService classMenuService;

    /**
     * 同步班级信息
     *
     * @param courseEntity 课程
     * @param oldCourseId  课程原ID
     * @param userId       同步用户Id
     */
    @Override
    public ClassDemoDTO initClass(CourseEntity courseEntity, Long oldCourseId, Long userId) {

        if (Objects.nonNull(courseEntity)) {
            return null;
        }

        // 获取班级信息
        LambdaQueryWrapper<ClassEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ClassEntity::getCourseId, oldCourseId);
        List<ClassEntity> classList = classMapper.selectList(wrapper);

        // 保存班级 前后ID
        ClassDemoDTO demoDTO = new ClassDemoDTO();
        demoDTO.setCourseId(courseEntity.getId());
        demoDTO.setCourseName(courseEntity.getCourseName());

        // 只获取 第一个班级数据进行同步
        ClassEntity entity = classList.get(0);
        demoDTO.setOldId(entity.getId());
        entity.setUserId(userId);
        entity.setCourseId(courseEntity.getId());
        Long newId = classService.insert(classConvert.newentity(entity));
        demoDTO.setId(newId);
        demoDTO.setClassName(entity.getName());

        // 同步班级学生
        this.initClassStudent(demoDTO, userId);

        // 同步审核记录
        this.initClassJoin(demoDTO);

        // 同步退课记录
        return demoDTO;
    }

    /**
     * 同步班级学生
     *
     * @param demoDTO 班级信息
     * @param userId  老师ID
     */
    private void initClassStudent(ClassDemoDTO demoDTO, Long userId) {
        LambdaQueryWrapper<ClassStudentEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ClassStudentEntity::getClassId, demoDTO.getOldId());
        List<ClassStudentEntity> students = classStudentMapper.selectList(wrapper);
        students.forEach(item -> {
            item.setId(null);
            item.setClassId(demoDTO.getId());
            item.setCourseId(demoDTO.getCourseId());
            item.setCreateBy(userId);
            item.setCreateTime(LocalDateTime.now());
            if (Objects.equals(ClassRoleEnum.TEACHER, item.getClassRole())) {
                item.setStudentId(userId);
            }
        });
        classStudentService.saveAllStudent(students);

        // 初始化群聊
        ClassEntity classEntity = new ClassEntity();
        classEntity.setId(demoDTO.getId());
        classEntity.setName(demoDTO.getClassName());
        this.initChatGroup(classEntity, students, userId);
    }

    /**
     * 创建班级群聊
     */
    private void initChatGroup(ClassEntity entity, List<ClassStudentEntity> students, Long userId) {
        List<Long> studentIds = students.stream().map(ClassStudentEntity::getStudentId).collect(Collectors.toList());
        classService.createClassChatGroup(entity, studentIds, userId);
    }

    /**
     * 加课退课记录
     */
    private void initClassJoin(ClassDemoDTO demoDTO) {
        // 生成加入班级信息
        LambdaQueryWrapper<ClassJoinAuditEntity> joinWrapper = new LambdaQueryWrapper();
        joinWrapper.eq(ClassJoinAuditEntity::getClassId, demoDTO.getOldId());
        List<ClassJoinAuditEntity> joinList = classJoinAuditMapper.selectList(joinWrapper);
        joinList.forEach(item -> {
            item.setId(null);
            item.setClassId(demoDTO.getId());
        });
        classJoinAuditService.saveAllBatch(joinList);

        // 生成操作记录信息
        LambdaQueryWrapper<ClassOperationLogEntity> logWrapper = new LambdaQueryWrapper();
        logWrapper.eq(ClassOperationLogEntity::getClassId, demoDTO.getOldId());
        List<ClassOperationLogEntity> logList = classOperationLogMapper.selectList(logWrapper);
        logList.forEach(item -> {
            item.setId(null);
            item.setCourseId(demoDTO.getCourseId());
            item.setClassId(demoDTO.getId());
        });
        classOperationLogService.batchSave(logList);
    }

    /**
     * 同步班级SQL语句
     *
     * @param userId   用户ID
     * @param courseId 课程ID
     */
    @Override
    public Long initClassSql(Long userId, Long courseId) {
        StringBuilder sql = new StringBuilder();
        // 生成班级
        Long classId = identifierGenerator.nextId(null).longValue();
        ClassEntity classEntity = new ClassEntity();
        classEntity.setId(classId);
        classEntity.setName("新奇一班");
        classEntity.setAuditMethod(ClassAuditEnum.MANUAL);
        classCode(classEntity);
        String classSql = "INSERT INTO cl_class(`id`, `create_by`, `create_time`, `update_by`, `update_time`, `is_delete`, `delete_time`, `version`, `school_id`" +
                ", `course_id`, `user_id`, `name`, `teaching_year`, `teaching_node`, `teaching_address`, `course_code`, `qr_code`, `status`, `audit_method`, `audit_info`" +
                ", `is_drop_class`, `is_student_count`, `student_count`, `is_name_editable`, `extend`)" +
                " VALUES (" + classId + ", " + userId + " , '2023-05-24 09:38:28', " + userId + ", '2023-05-30 11:43:43', 0, 0, 0, NULL, " + courseId + ", " + userId +
                ", '新奇一班', '2023-2024', '全年', NULL, '" + classEntity.getCourseCode() + "', '" + classEntity.getQrCode() + "', 'NORMAL', 'MANUAL', '[\"学生姓名\", \"身份\", \"手机号\", \"学号\"]', 1, 1, 50, 1, NULL);";
        sql.append(classSql);

        // 生成班级学生信息SQL
        this.initClassStudentsSql(sql, userId, courseId, classId);
        // 生成加入班级信息
        this.initClassJoinSql(sql, userId, courseId, classId);
        // 操作记录
        this.initOperationSql(sql, userId, courseId, classId);

        // 执行SQL
        courseMapper.insertAllSql(sql.toString());

        // 生成菜单
        classMenuService.initClassMenu(classId, courseId);

        // 生成群聊信息
        Long[] studentIds = new Long[]{1645972241733963777L, 1650458704827445249L, 1653986821394567169L, 1654693737893134337L
                , 1655410589569056769L, 1655650372358701057L, 1656548738307391489L, 1659403958154625026L, 1661185385489694721L};
        classService.createClassChatGroup(classEntity, Arrays.asList(studentIds), userId);

        return classId;
    }

    /**
     * 生成班级学生信息
     */
    private void initClassStudentsSql(StringBuilder sql, Long userId, Long courseId, Long classId) {
        List<Long> classStudentIds = new ArrayList<>();
        for (int i = 0; i < 11; i++) {
            Long classStudentId = identifierGenerator.nextId(null).longValue();
            classStudentIds.add(classStudentId);
        }
        String classStudentSql = "INSERT INTO cl_class_student(`id`, `create_by`, `create_time`, `update_by`, `update_time`, `school_id`, `course_id`, `class_id`, `student_id`, `is_archive`, `is_top`, `is_teacher_top`, `is_student_top`, `is_teacher`, `class_role`, `audit_content`) " +
                "VALUES (" + classStudentIds.get(0) + ", 1645325062446964737, '2023-05-24 09:38:28', 1645325062446964737, '2023-05-24 09:38:28', NULL, " + courseId + ", " + classId + ", " + userId + ", 0, 0, 0, 0, 1, 'TEACHER', NULL)," +
                "(" + classStudentIds.get(1) + ", 1645325062446964737, '2023-05-30 11:43:11', 1645325062446964737, '2023-05-30 11:43:18', NULL, " + courseId + ", " + classId + ", 1645972241733963777, 0, 0, 0, 0, 1, 'ASSISTANT', NULL)," +
                "(" + classStudentIds.get(2) + ", 1650458704827445249, '2023-05-24 09:43:21', 1645325062446964737, '2023-05-30 11:36:58', NULL, " + courseId + ", " + classId + ", 1650458704827445249, 0, 0, 0, 0, 0, 'REPRESENTATIVE', NULL)," +
                "(" + classStudentIds.get(3) + ", 1645325062446964737, '2023-05-28 17:48:40', 1645325062446964737, '2023-05-28 17:48:40', NULL, " + courseId + ", " + classId + ", 1653986821394567169, 0, 0, 0, 0, 0, 'STUDENT', NULL)," +
                "(" + classStudentIds.get(4) + ", 1654693737893134337, '2023-05-24 09:55:29', 1654693737893134337, '2023-05-24 09:55:29', NULL, " + courseId + ", " + classId + ", 1654693737893134337, 0, 0, 0, 0, 0, 'STUDENT', NULL)," +
                "(" + classStudentIds.get(5) + ", 1645325062446964737, '2023-05-28 18:14:49', 1645325062446964737, '2023-05-28 18:14:49', NULL, " + courseId + ", " + classId + ", 1655410589569056769, 0, 0, 0, 0, 0, 'STUDENT', NULL)," +
                "(" + classStudentIds.get(6) + ", 1645325062446964737, '2023-05-28 18:17:53', 1645325062446964737, '2023-05-28 18:17:53', NULL, " + courseId + ", " + classId + ", 1655650372358701057, 0, 0, 0, 0, 0, 'STUDENT', NULL)," +
                "(" + classStudentIds.get(7) + ", 1645325062446964737, '2023-05-28 18:06:17', 1656548738307391489, '2023-06-01 09:15:04', NULL, " + courseId + ", " + classId + ", 1656548738307391489, 0, 0, 0, 0, 0, 'STUDENT', NULL)," +
                "(" + classStudentIds.get(8) + ", 1659403958154625026, '2023-05-28 18:08:07', 1659403958154625026, '2023-05-28 18:08:07', NULL, " + courseId + ", " + classId + ", 1659403958154625026, 0, 0, 0, 0, 0, 'STUDENT', NULL)," +
                "(" + classStudentIds.get(9) + ", 1645325062446964737, '2023-05-24 09:42:06', 1645325062446964737, '2023-05-24 09:42:06', NULL, " + courseId + ", " + classId + ", 1661185385489694721, 0, 0, 0, 0, 0, 'STUDENT', NULL);";
        sql.append(classStudentSql);
    }

    /**
     * 生成班级学生加入信息
     */
    private void initClassJoinSql(StringBuilder sql, Long userId, Long courseId, Long classId) {
        String joinSql = "INSERT INTO cl_class_join_audit(`id`, `create_by`, `create_time`, `update_by`, `update_time`, `is_delete`, `delete_time`, `class_id`, `student_id`, `status`, `audit_user_id`, `audit_time`, `audit_content`, `audit_result`) " +
                "VALUES (" + identifierGenerator.nextId(userId) + ", 1661185385489694721, '2023-05-24 09:41:55', 1645325062446964737, '2023-05-24 09:42:06', 0, 0, 1661184856792928257, 1661185385489694721, 'PASS', 1645325062446964737, '2023-05-24 09:42:06', '[{\"姓名\": \"新奇学员09\"}, {\"学号\": \"20230818009\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000009\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1650458704827445249, '2023-05-24 09:43:21', 1650458704827445249, '2023-05-24 09:43:21', 0, 0, 1661184856792928257, 1650458704827445249, 'PASS', 1650458704827445249, '2023-05-24 09:43:21', '[{\"姓名\": \"新奇学员02\"}, {\"学号\": \"20230818002\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000002\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1654693737893134337, '2023-05-24 09:55:29', 1654693737893134337, '2023-05-24 09:55:29', 0, 0, 1661184856792928257, 1654693737893134337, 'PASS', 1654693737893134337, '2023-05-24 09:55:29', '[{\"姓名\": \"新奇学员04\"}, {\"学号\": \"20230818004\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000004\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-28 17:48:40', 1645325062446964737, '2023-05-28 17:48:40', 0, 0, 1661184856792928257, 1653986821394567169, 'PASS', 1645325062446964737, '2023-05-28 17:48:40', '[{\"姓名\": \"新奇学员03\"}, {\"学号\": \"20230818003\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000003\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-28 18:06:17', 1645325062446964737, '2023-05-28 18:06:17', 0, 0, 1661184856792928257, 1656548738307391489, 'PASS', 1645325062446964737, '2023-05-28 18:06:17', '[{\"姓名\": \"新奇学员07\"}, {\"学号\": \"20230818007\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000007\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1659403958154625026, '2023-05-28 18:08:07', 1659403958154625026, '2023-05-28 18:08:07', 0, 0, 1661184856792928257, 1659403958154625026, 'PASS', 1659403958154625026, '2023-05-28 18:08:07', '[{\"姓名\": \"新奇学员08\"}, {\"学号\": \"20230818008\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000008\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-28 18:14:49', 1645325062446964737, '2023-05-28 18:14:49', 0, 0, 1661184856792928257, 1655410589569056769, 'PASS', 1645325062446964737, '2023-05-28 18:14:49', '[{\"姓名\": \"新奇学员05\"}, {\"学号\": \"20230818005\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000005\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-28 18:17:53', 1645325062446964737, '2023-05-28 18:17:53', 0, 0, 1661184856792928257, 1655650372358701057, 'PASS', 1645325062446964737, '2023-05-28 18:17:53', '[{\"姓名\": \"新奇学员06\"}, {\"学号\": \"20230818006\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000006\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-30 11:43:11', 1645325062446964737, '2023-05-30 11:43:11', 0, 0, 1661184856792928257, 1645972241733963777, 'PASS', 1645325062446964737, '2023-05-30 11:43:11', '[{\"姓名\": \"新奇学员01\"}, {\"学号\": \"20230818001\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000001\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-30 11:43:11', 1645325062446964737, '2023-05-30 11:43:11', 0, 0, 1661184856792928257, 1656486577568677889, 'REJECT', 1645325062446964737, '2023-05-30 11:43:11', '[{\"姓名\": \"新奇学员10\"}, {\"学号\": \"20230818010\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000010\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-30 11:43:11', 1645325062446964737, '2023-05-30 11:43:11', 0, 0, 1661184856792928257, 1656486577568677890, 'REJECT', 1645325062446964737, '2023-05-30 11:43:11', '[{\"姓名\": \"新奇学员11\"}, {\"学号\": \"20230818011\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000011\"}]', NULL)," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-30 17:09:35', 1645325062446964737, '2023-05-30 17:10:06', 0, 0, 1661184856792928257, 1656486577568677891, 'REJECT', 1645325062446964737, '2023-05-30 17:10:06', '[{\"姓名\": \"新奇学员12\"}, {\"学号\": \"20230818012\"}, {\"学校\": \"新奇课堂模拟学院\"}, {\"手机\": \"19200000012\"}]', NULL);";
        joinSql = joinSql.replaceAll("1661184856792928257", classId.toString());
        sql.append(joinSql);
    }

    /**
     * 生成班级学生加入信息
     */
    private void initOperationSql(StringBuilder sql, Long userId, Long courseId, Long classId) {
        String operationSql = "INSERT INTO cl_class_operation_log(`id`, `create_by`, `create_time`, `update_by`, `update_time`, `is_delete`, `delete_time`, `course_id`, `class_id`, `student_id`, `type`, `audit_id`, `is_top`, `is_teacher`, `class_role`) " +
                "VALUES (" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-24 09:42:06', 1645325062446964737, '2023-05-24 09:42:06', 0, 0, 1661184856092479489, 1661184856792928257, 1661185385489694721, 'AUDIT_JOIN', 1661185725831745538, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1650458704827445249, '2023-05-24 09:43:21', 1650458704827445249, '2023-05-24 09:43:21', 0, 0, 1661184856092479489, 1661184856792928257, 1650458704827445249, 'AUTO_JOIN', 1661186087061983234, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1654693737893134337, '2023-05-24 09:55:29', 1654693737893134337, '2023-05-24 09:55:29', 0, 0, 1661184856092479489, 1661184856792928257, 1654693737893134337, 'AUTO_JOIN', 1661189140494323713, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-28 17:48:40', 1645325062446964737, '2023-05-28 17:48:40', 0, 0, 1661184856092479489, 1661184856792928257, 1653986821394567169, 'MOVE_IN', 1662757773611798529, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-28 18:06:17', 1645325062446964737, '2023-05-28 18:06:17', 0, 0, 1661184856092479489, 1661184856792928257, 1656548738307391489, 'MOVE_IN', 1662762206642999298, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1659403958154625026, '2023-05-28 18:08:07', 1659403958154625026, '2023-05-28 18:08:07', 0, 0, 1661184856092479489, 1661184856792928257, 1659403958154625026, 'AUTO_JOIN', 1662762664619053057, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-28 18:09:16', 1645325062446964737, '2023-05-28 18:09:16', 0, 0, 1661184856092479489, 1661184856792928257, 1645599603325669377, 'MOVE_IN', 1662762954747449345, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-28 18:14:49', 1645325062446964737, '2023-05-28 18:14:49', 0, 0, 1661184856092479489, 1661184856792928257, 1655410589569056769, 'MOVE_IN', 1662764351605870593, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-28 18:17:53', 1645325062446964737, '2023-05-28 18:17:53', 0, 0, 1661184856092479489, 1661184856792928257, 1655650372358701057, 'MOVE_IN', 1662765124104392705, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-30 11:43:11', 1645325062446964737, '2023-05-30 11:43:11', 0, 0, 1661184856092479489, 1661184856792928257, 1645972241733963777, 'MOVE_IN', 1663390569019006978, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1645325062446964737, '2023-05-31 09:22:15', 1645325062446964737, '2023-05-31 09:22:15', 0, 0, 1661184856092479489, 1661184856792928257, 1645331606556119041, 'AUDIT_JOIN', 1663717434560667650, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1645331606556119041, '2023-05-31 09:23:20', 1645331606556119041, '2023-05-31 09:23:20', 0, 0, 1661184856092479489, 1661184856792928257, 1645331606556119041, 'QUIT', NULL, 0, 0, 'STUDENT')," +
                "(" + identifierGenerator.nextId(userId) + ", 1645599603325669377, '2023-05-31 15:38:57', 1645599603325669377, '2023-05-31 15:38:57', 0, 0, 1661184856092479489, 1661184856792928257, 1645599603325669377, 'QUIT', NULL, 0, 0, 'STUDENT');";
        operationSql = operationSql.replaceAll("1661184856092479489", courseId.toString());
        operationSql = operationSql.replaceAll("1661184856792928257", classId.toString());
        sql.append(operationSql);
    }

    private ClassEntity classCode(ClassEntity entity) {
        // 设置 加课码
        entity.setCourseCode(RandomUtils.randomStrUp(6));
        Map<String, Object> mapData = new HashMap<>();
        mapData.put("type", QrCodeEnum.QR_ADD_CLASS.getCode());
        mapData.put("code", entity.getCourseCode());
        mapData.put("auditMethod", entity.getAuditMethod());
        String genQrCodeUrl = RedisUtils.getCacheMapValue(CacheConstants.SYS_CONFIG_HASH_KEY, ConfigKeyConstants.SYS_GEN_QRCODE_URL);
        String content = genQrCodeUrl + JSON.stringify(mapData);
        entity.setQrCode(content);
        return entity;
    }
}
